/*
 * Copyright (c) 2009. Silenus Consultoria, S.L.
 */
package es.silenus.detecta.dao.impl;

import es.silenus.detecta.dao.SurveyAnswerHeaderDAO;

import es.silenus.detecta.model.SurveyAnswerHeader;

import org.hibernate.Session;

import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;


/**
 * DOCUMENT ME!
 *
 * @author <a href="mailto:dgarcia@silenus-consultoria.es">Daniel Garc&iacute;a</a>
 *
 * @since 02-abr-2009 12:44:50
 */
public class SurveyAnswerHeaderDAOImpl extends ReadWriteDAOImpl<SurveyAnswerHeader, Long>
	implements SurveyAnswerHeaderDAO {
	/**
	 * Checks if a given entity id has filled in a given survey.
	 *
	 * @param surveyId the survey id.
	 * @param entityId the entity id.
	 *
	 * @return true or false.
	 */
	@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
	public boolean hasEntity(int surveyId, String entityId) {
		Session session = null;

		try {
			session = getSession();

			return session.getNamedQuery(SurveyAnswerHeader.class.getName() + ".hasEntity").setInteger("surveyId", surveyId)
										.setString("entityId", entityId).uniqueResult() != null;
		} finally {
			releaseSession(session);
		}
	}
}
